import { ref, onBeforeUnmount, onMounted, reactive, getCurrentInstance } from 'vue'
import { getWordList_api } from '@/common/apis/spoken'
import { usePagination } from '@/common/hooks/usePagination'
import { onLoad, onShareAppMessage } from "@dcloudio/uni-app"


export default function useInit() {
	const { proxy } = getCurrentInstance()
	const { user,store_config } = proxy.$store()
	const reqdata = reactive({id: 0})
	const readylist = reactive([])
	const swiperindex = ref()
	const swiperDuration = ref(0)
	const {
		list: flowlist,
		loadmore,
		message,
		loading,
		refresh
	} = usePagination(getWordList_api, {
		transform: res => {
			res.forEach(item => {
				delete item.status
				item.word = item.word.replace(/\s+/g, '');
				if(item.answerFile){
					readylist.push(item)
				}
			})
			return res
		},
		defaultParam: reqdata,
		auto: false,
	});
	
	onLoad(async o => {
		reqdata.id = o.logId
		await refresh()
		for (let i = 0; i < flowlist.value.length; i++) {
			if (!flowlist.value[i].answerFile) {
				swiperindex.value = i
				break;
			} else{
				swiperindex.value = i
			}
		}
		swiperDuration.value = 300
	})
	
	// const {
	// 	list,
	// 	loadmore,
	// 	message,
	// 	loading,
	// 	refresh
	// }
	
	return {
		flowlist,
		readylist,
		swiperindex,
		swiperDuration,
		reqdata,
		loading
	};
}